﻿using Microsoft.AspNet.Mvc.Facebook;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

// Add any fields you want to be saved for each user and specify the field name in the JSON coming back from Facebook
// http://go.microsoft.com/fwlink/?LinkId=301877

namespace MakeWeekConcerts.Models
{
    public class FacebookUser
    {
        public string Id { get; set; }
        public string Name { get; set; }
        public string Email { get; set; }

        [JsonProperty("picture")] // This renames the property to picture.
        //[FacebookFieldModifier("type(large)")] // This sets the picture size to large.
        public FacebookConnection<FacebookPicture> ProfilePicture { get; set; }

        //[FacebookFieldModifier("limit(50)")]
        public FacebookGroupConnection<FacebookLike> Music { get; set; }

        //[FacebookFieldModifier("limit(50)")] // This sets the size of the friend list to 8, remove it to get all friends.
        public FacebookGroupConnection<SimpleFacebookFriend> Friends { get; set; }

        public async Task<Dictionary<string, HashSet<string>>> FindSimilarArtists(double minimumSimilarityThreshold = 0.3)
        {
            var myArtists = new HashSet<string>(this.Music.Data.Select(x => x.Name), StringComparer.OrdinalIgnoreCase);

            var mySimilar = new Dictionary<string, HashSet<string>>(StringComparer.OrdinalIgnoreCase);
            foreach (var artist in myArtists)
            {
                var similar = await DataLoader.FindSimilarArtistsAsync(artist);
                var curSimilar = new HashSet<string>(similar.SimilarArtists.Artists.Where(x => x.Match > minimumSimilarityThreshold).Select(x => x.Name), StringComparer.OrdinalIgnoreCase);
                mySimilar[artist] = curSimilar;
            }

            return mySimilar;
        }
    }
}
